        TITL DAI FIRMWARE D790-D8FA  V1.1
        ORG   :D790
*
*
*
************************
* CHECK FREE RAM SPACE *
************************
*
* Entry: DE: Startaddress.
*        HL: 1st not useable address.
* Exit:  HL: Useable RAM space.
*        ABCDE preserved.
*
MPT25   CALL  SUBDE     Calculate free space
        DCX   H
        RET 
*
**********************************
* TRANSFER DATA/CASSETTE VECTORS *
**********************************
*
* Transfer data/cassette switching vectors from
* ROM to RAM vector area.
*
* Exit: AFBC preserved. DEHL corrupted.
*
*MPT01
CASIN   PUSH  B
        LXI   H,WPT     Highest source address
        LXI   D,CINTB   Lowest source address
        LXI   B,WOPEN   Lowest destination address
        CALL  MOVE      Transfer cassette vectors
        POP   B
        RET 
*
***********************************
* DATA/CASSETTE SWITCHING VECTORS *
***********************************
*
* This data block is moved into the RAM area
* #02C5-#02EB during system initialisation.
*
CINTB   JMP   CWOPEN    WOPEN
        JMP   CWBLK     WBLK
        JMP   CWCLOS    WCLOSE
        JMP   CROPEN    ROPEN
        JMP   CRBLK     RBLK
        JMP   CRCLOS    RCLOSE
        JMP   CMBLK     MBLK
        RET             RESET
        NOP 
        NOP 
        RET             DOUTC
        NOP 
        NOP 
        JMP   INSER     DINC
        RET 
        NOP 
        NOP 
        DATA  :24,:24   TAPSL
        DATA  :24,:3C   TAPSD
        DATA  :24,:18   TAPST
*
************************************
* WAIT FOR SPACEBAR, PRINT CAR.RET *
************************************
*
* Exit: BCDEHL preserved.
*       CY=1: Break pressed.
*
*CINTE
WPT     CALL  WSPACE    Wait for spacebar
        JC    RSTART    If BREAK pressed: into
 REM Basic monitor
        JMP   CRLF      Print car.ret; ret
*
        DATA  :FF
        DATA  :FF
        DATA  :FF
        DATA  :FF
*
*********************************
* WRITE BLOCK + TRAILER ON TAPE *
*********************************
*
* Entry: DE: Length block.
*        HL: Startaddress block.
* Exit:  A=0, BCDE preserved.
*        HL points past block written.
*
MPT10   CALL  WBLK      Write block
        JMP   WCLOSE    Write trailer
*
************************
* FAILURE DURING ROPEN *
************************
*
RPN20   DCR   C
        INR   C         Load during program ?
        CNZ   CRLF      Print car.ret if not
        JMP   RPN10     Back to read file leader
*
*****************************
* PRINT MESSAGE ON NEW LINE *
*****************************
*
* New routine. It moves the cursor to a new line
* before a message is printed. Used for printing
* 'STOPPED IN LINE ...' and 'END PROGRAM'.
*
PMSGN   CALL  COL0      ] Cursor to column 0
        JMP   PMSGR     ] Print message
*
*****************
* FAST PRINTING *
*****************
*
* Instruction only moved.
*
FPRNT   PUSH  H
        LHLD  CURSOR    Get cursor position address
        MOV   M,A       Write byte on screen
        DCX   H         ) Update cursor addr
        DCX   H         )
        SHLD  CURSOR    Save new cursor address
        POP   H
        RET 
*
***************************
* SAVE: WRITE NAME LENGTH *
***************************
*
* Entry: HL: Addr. length byte of name.
* Exit:  DE: Length of name.
*        HL: Points past string.
*        BC: Preserved.
*        A:  Checksum on string.
*
MPT22   MOV   E,M       Get name length
        MVI   D,:00
        INX   H         HL to 1st byte of name
        JMP   CWBLK     Write name length
*
********************************
* INITIALISE LOADING FROM TAPE *
********************************
*
* Entry: HL: Points to length byte of name requested
* Exit:  DE: Length requested name.
*        HL: Points to first byte of name.
*        AFBC preserved.
*
MPT23   MOV   E,M       Get length requested name
        MVI   D,:00     in DE
        INX   H         HL points to 1st byte name
        JMP   CASST     Cassette motors on; ret
*
*********************
* UPDATE POROM/PORO *
*********************
*
* Entry: MPT52: Byte for ROM/cassette select in A.
*        MPT53: New POROM byte.
*
MPT52   ANI   :F0       Enable ROM/cassette select
MPT53   STA   POROM     Load POROM
        STA   PORO      and PORO
        RET 
*
*****************
* part of 2EAC1 *
*****************
*
* If pointer is off top visible screen:
*
PCK40   MOV   A,D
        CPI   :D0
        JC    PCK30     (2) if <= CF (no overflow
 REM below 0)
        PUSH  H         ) if > CF:
        PUSH  B         ) Exchange BC and HL
        POP   H         )
        POP   B         )
        JMP   PCK30     (2)
*
        DATA  :FF
*
**********************
* RUN basiccmd SAVEA *
**********************
*
RSAVA   CALL  RLSAS     Evaluate array type to be
 REM saved
        PUSH  PSW       Save type array
        JNZ   LD99      Jump if INT/FPT array
        RST   4         Move stringarray into one
        DATA  :75       string in free RAM
LD99    POP   PSW       Get type array
        PUSH  H
        PUSH  D
        PUSH  PSW
        CALL  REXSR     (0) Evaluate program name
        MVI   A,:32     File type byte '2'
        CALL  WOPEN     WOPEN
        POP   PSW       Get type array
        LXI   H,EBUF    Startaddr EBUF
        MOV   M,A       Type into EBUF
        JMP   MPT13     Write 2 blocks + trailer
*
        NOP 
*
******************************************
* EVALUATE ARRAY TYPE TO BE SAVED/LOADED *
******************************************
*
* Exit: A:   Array type.
*       DE:  Length all array elements.
*       HL:  Beginaddr. 1st array element.
*       Z=1: String array.
*       Z=0: INT/FPT array.
*
RLSAS   CALL  RARRN     (0) Get array addr in HL
        ANI   :30       Allow any type array
        PUSH  PSW       Save type
        MOV   E,M       )
        INX   H         ) Get array pntr in DE
        MOV   D,M       )
        MOV   A,E
        ORA   D
        JZ    ERRUA     (0) Undef. array if no addr
        XCHG            Pointer to array in HL
        DCX   H
        DCX   H
        MOV   D,M       Get 1st length byte
        INX   H
        MOV   A,M       Get 2nd length byte
        INX   H
        SUB   M         Minus nr of dim. bytes
        MOV   E,A
        MOV   A,D
        SBI   :00       Update hibyte if borrow
        MOV   D,A
        DCX   D         DE is length all array elem.
        CALL  DADM      HL is beginaddr 1st element
        POP   PSW       Get type in A
        CPI   :20       Set Z-flag on type
        RET 
*
**********************
* RUN basiccmd LOADA *
**********************
*
RLODA   CALL  RLSAS     Evaluate array type to be
 REM loaded
        PUSH  H         Save startaddr array elem.
        PUSH  PSW       Save type
        CALL  MPT14     Evaluate requested program
 REM name; prep. select ROM bank
        CALL  MPT53     Select ROM bank 1
        POP   PSW       Get type
        JMP   L1E273    (1) Read block from tape and
 REM store it in array
*
************************************
* INITIALISE 'EDIT': EMPTY HEAP,   *
* CLEAR SYMBOL TABLE, MOVE PROGRAM *
************************************
*
* Part of 'Init. EDIT' (0E265).
*
* Entry: CY=1: Not sufficient memory available.
*
MPT33   JC    ERROM     Evt. run error 'OUT OF
 REM MEMORY'
        JMP   SCRATC    Empty heap, move
 REM program, clear symtab
*
******************************************
* LIST CURRENT LINE IF LINENR IS CORRECT *
******************************************
*
* Part of 'run LIST <range>' (0E1B6).
*
* Entry: CY=0 if linenr. <= 0 or > FFFF.
*
MPT3A   JNC   ERRRA     Evt. run error 'NUMBER
 REM OUT OF RANGE'
        JMP   SLINE     (0) List current line
*
**************************
* INPUT FROM EDIT BUFFER *
**************************
*
* Part of 'restart interpreter' (C823).
*
MPT05   PUSH  H
        CALL  IFBNL     (0) Input from editbuffer
        POP   H
        RET 
*
*******************************
* part of RUN 'CLEAR' (0E6B5) *
*******************************
*
* Checks for heap too big.
*
MPT42   POP   H         ] Get difference
        DAD   B         ] Add textpntr
        MOV   B,H       ] New textpntr in BC
        MOV   C,L       ]
        ORA   A         ] No special action
        RET             ]
        DATA  :FF       ]
*
************************************
* EVT. INITIALISE 4 COLOUR ANIMATE *
************************************
*
* Part of 2E9C3.
*
SPT04   CPI   :14
        RNC             Abort if A >= 14
        STA   TEXTCL    Set for 4-colour animate
        RET 
*
********
* DATA *
********
*
LD221   DATA  :20       Space
        DATA  :8C,:72   Pntr. to 'MODE'
        DATA  :00
*
******************************
* part of 1EE0B - (not used) *
******************************
*
LD105   PUSH  PSW
        CALL  REXSR     (1)
        POP   PSW
        RET 
*
*******************************************
* READ BLOCK FROM TAPE, EVT. ERROR REPORT *
*******************************************
*
* Part of LOADA (1EE0F).
*
MPT19   CALL  RBLK      Read block from tape
*
************************
* READ BLOCK FROM TAPE *
************************
*
* Now cassette motors are switched off directly
* after reading is finished.
* Especially in LOADA, switching off the cassette
* motors after re-arranging all data was very
* annoying.
*
        JMP   RSVEX     Evt. run 'LOADING ERROR'
        RET 
*
**************************************
* LIST ARRAY NAME, SPACE, EXPRESSION *
**************************************
*
* Used in listing 'Savea/Loada' textlines.
*
SCN30   CALL  SCARN     (0) List array name
        JMP   SCSEX     (0) List space, expression
*
        DATA  :FF
        DATA  :FF
*
******************************
* INITIALISE SOUND GENERATOR *
******************************
*
* All sound channels are switched off.
*
* Exit: AB preserved, CDEHLF corrupted.
*
SNDINI  LXI   H,PITCW
        MVI   M,:36     ) Load 3 timers
        MVI   M,:76     )
        MVI   M,:B6     )
        LXI   H,:0000
        SHLD  POR0      Volume 4 channels off
        SHLD  POR0M     and remember it
        LXI   H,SCB0    Start 1st SCB
        LXI   D,:000E   Length SCB
        MVI   C,:04     4 blocks (3 SCB, 1 NCB)
SNI10   MVI   M,:FF     FF in 1st byte SCB (= off)
        DAD   D         Calc start next block
        DCR   C
        JNZ   SNI10     Next block if not ready
        RET 
*
*********************
* OUTPUT TO DCE-BUS *
*********************
*
* 'Real World' output. Writes a byte to a given
* Real World address.
*
* Entry: D: Busaddress.
*        E: Data for output.
*
RWOP    PUSH  PSW
        PUSH  H
        LXI   H,GICCW   GIC control address
        MVI   M,:80     All ports output
        DCX   H         Port C addr. in HL
        MVI   M,:FE     Clear bus expand signal
        XCHG            Data in L, busaddr. in H
        SHLD  GIC       Data in PA, busaddr. in PB
        XCHG            Address PC in HL
        INR   M         Set bus expand signal
        MVI   M,:FD     Set write strobe true
 REM (Now data exchange done)
        MVI   M,:FF     Reset strobe
        DCR   M         Clear bus expand signal
        POP   H
        POP   PSW
        RET 
*
**********************
* INPUT FROM DCE-BUS *
**********************
*
* 'Real World' input. Reads a byte from a given
* Real World address.
*
* Entry: D: Busaddress.
* Exit:  E: Data received.
*
RWIP    PUSH  PSW
        PUSH  H
        LXI   H,GICCW   GIC control addr. in HL
        MVI   M,:90     PA input, rest output
        DCX   H         Address PC in HL
        MVI   M,:FE     Clear bus expand signal
        MOV   A,D       Busaddress in A
        STA   GICPB     Store busaddress in PB
        INR   M         Set bus expand signal
        MVI   M,:FB     Set read strobe true
 REM (Now data exchange)
        LDA   GIC       Data to A
        MOV   E,A       Data in E
        MVI   M,:FF     Reset strobe
        DCR   M
        POP   H
        POP   PSW
        RET 
*
*
*
        UNL
SUBDE   EQU   :DE1A
WOPEN   EQU   :02C5
MOVE    EQU   :DE4F
CWOPEN  EQU   :D2B8
CWBLK   EQU   :D2F1
CWCLOS  EQU   :D427
CROPEN  EQU   :D325
CRBLK   EQU   :D340
CRCLOS  EQU   :D445
CMBLK   EQU   :D3A2
INSER   EQU   :DDB4
WSPACE  EQU   :D6DA
RSTART  EQU   :C80C
CRLF    EQU   :DD5E
WBLK    EQU   :02C8
WCLOSE  EQU   :02CB
RPN10   EQU   :D329
COL0    EQU   :DD55
PMSGR   EQU   :DAFF
CURSOR  EQU   :0072
CASST   EQU   :D42E
POROM   EQU   :0040
PORO    EQU   :FD06
PCK30   EQU   :EAEF
REXSR   EQU   :E791
EBUF    EQU   :013E
MPT13   EQU   :D668
RARRN   EQU   :E95A
ERRUA   EQU   :E990
DADM    EQU   :DE39
MPT14   EQU   :D678
L1E273  EQU   :EE0F
ERROM   EQU   :DA10
SCRATC  EQU   :CB23
ERRRA   EQU   :DA15
SLINE   EQU   :ECAB
IFBNL   EQU   :E291
TEXTCL  EQU   :00C1
RBLK    EQU   :02D1
RSVEX   EQU   :D265
SCARN   EQU   :EEF7
SCSEX   EQU   :ED65
PITCW   EQU   :FC06
POR0    EQU   :FD04
POR0M   EQU   :0294
SCB0    EQU   :01C2
GICCW   EQU   :FE03
GIC     EQU   :FE00
GICPB   EQU   :FE01
        LST
        END 
